<template>
   <div class="login">
    <el-form ref="pwdRef" :model="user" :rules="rules" class="login-form">
      <div class="title-head">
      <div class="logo"><img src="../assets/logo/logo.png" alt=""></div> <h3 class="title">课程开出率管理系统</h3>
     </div>
     <div class="back-title">
      <router-link class="link-type" :to="'/'"  style="" > <img src="../assets/images/login_ico_back.png" alt=""> </router-link> <div class="b-title">重置密码</div>
     
     </div>
    <el-form-item  prop="oldPassword">
      <el-input v-model="user.oldPassword" placeholder="请输入旧密码" type="password" show-password >
       <template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
      </el-input>
    </el-form-item>
    <el-form-item  prop="newPassword">
      <el-input v-model="user.newPassword" placeholder="请输入新密码" type="password" show-password >
       <template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
      </el-input>
    </el-form-item>
    <el-form-item  prop="confirmPassword">
      <el-input v-model="user.confirmPassword" placeholder="请确认新密码" type="password" show-password >
       <template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
      </el-input>
    </el-form-item>
    <el-form-item style="width: 100%; ">
      <el-button size="large" type="primary" style="width: 100% ;height: 65px; line-height: 65px; font-size: 19px ; background: #05AFEA; border-radius: 14px; margin-top:40px" @click="submit">确定</el-button>
      <!-- <el-button type="danger" @click="close">关闭</el-button> -->
    </el-form-item>
  </el-form>
  </div>
  
</template>

<script setup lang="ts">
import { updateUserPwd } from '@/api/system/user';
import type { ResetPwdForm } from '@/api/system/user/types';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const pwdRef = ref<ElFormInstance>();
const user = ref<ResetPwdForm>({
  oldPassword: '',
  newPassword: '',
  confirmPassword: ''
});

const equalToPassword = (rule: any, value: string, callback: any) => {
  if (user.value.newPassword !== value) {
    callback(new Error('两次输入的密码不一致'));
  } else {
    callback();
  }
};
const rules = ref({
  oldPassword: [{ required: true, message: '旧密码不能为空', trigger: 'blur' }],
  newPassword: [
    { required: true, message: '新密码不能为空', trigger: 'blur' },
    {
      min: 6,
      max: 20,
      message: '长度在 6 到 20 个字符',
      trigger: 'blur'
    },
    { pattern: /^[^<>"'|\\]+$/, message: '不能包含非法字符：< > " \' \\\ |', trigger: 'blur' }
  ],
  confirmPassword: [
    { required: true, message: '确认密码不能为空', trigger: 'blur' },
    {
      required: true,
      validator: equalToPassword,
      trigger: 'blur'
    }
  ]
});

/** 提交按钮 */
const submit = () => {
  pwdRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      await updateUserPwd(user.value.oldPassword, user.value.newPassword);
      proxy?.$modal.msgSuccess('修改成功');
    }
  });
};
/** 关闭按钮 */
const close = () => {
  proxy?.$tab.closePage();
};
</script>
<style lang="scss" scoped>
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height:100%;
  background: image-set(
      url('../assets/images/login_bg.png') 1x,
      url('../assets/images/login_bg@2x.png') 2x
    ) no-repeat;
  background-size: cover ,cover;
  // padding-right:260px;
  padding-left: 42vw;
}
.title-head{
  display: flex;
  align-items: center;
  // margin: 0px auto 30px auto;
  .title {
 margin-left: 20px;
  text-align: center;
  font-size: 32px;
color: #141414;
line-height: 45px;
font-weight: bold;
}
}
.back-title{
  display: flex;
  align-items: center;
 margin: 10px 0 40px;
  img{
    width: 14px;
    height: 24px;
    vertical-align: middle;
  }
  .b-title{
    font-size: 23px; color: #141414; 
    line-height: 32px; 
    margin-left: 14px;
  }

}

.login-form {
  box-sizing: border-box;
  width: 580px;
  // height: 675px;
  background: #FFFFFF;
  box-shadow: 0px 4px 10px 13px rgba(119,168,245,0.11);
  border-radius: 26px;
  padding:18px 67px 52px;
  :deep(.el-tabs__item){
    font-size: 23px !important;
    color: #999999;
    line-height: 32px;
    font-weight: 500;
  }
  :deep(.el-tabs__item.is-active, .el-tabs__item:hover){
  
   color: #141414 !important;

  }

.el-form-item{
  margin-bottom: 24px !important;
}
.el-select__wrapper{
  padding: 12px 12px;
  height: 55px;
  font-size: 16px;
  background: #F6F6F7;
border-radius: 14px;
}
:deep(.el-input__wrapper){
  background: #F6F6F7;
  border-radius: 14px;
}
  .el-input {
    height: 55px;
    font-size: 16px;
    background: #F6F6F7;
border-radius: 14px;
    input {
      height: 55px;
      font-size: 16px;
      background: #F6F6F7;
border-radius: 14px;
    }
  }

  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 0px;
  }
}

.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}

.login-code {
  width: 33%;
  height: 55px;
  float: right;

  img {
    cursor: pointer;
    vertical-align: middle;
  }
}

.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial, serif;
  font-size: 12px;
  letter-spacing: 1px;
}

.login-code-img {
  height:55px;
  padding-left: 12px;
}
.linkLogin{
 text-align: center;
 .link-text{

  font-size: 14px;
color: #999999;
line-height: 20px;
 }
}
/* 可选：如果你还想移除标签项下方的线条 */
.el-tabs__nav-wrap::after {
  display: none; /* 隐藏标签项下方的线条 */
}
@media screen and (max-width: 1200px) {
  .login{
    justify-content: center;
    padding: 0;
  }
}
</style>
